package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatGodClass;
import com.happy.cat.project.system.service.ICatGodClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 大神评论标签Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/class" )
@Api("大神评论标签 API")
public class CatGodClassController extends BaseController {

    private final ICatGodClassService iCatGodClassService;

    /**
     * 查询大神评论标签列表
     */
    @ApiOperation(value = "查询大神评论标签列表",notes = "查询大神评论标签列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatGodClass catGodClass)
    {
        startPage();
        LambdaQueryWrapper<CatGodClass> lqw = new LambdaQueryWrapper<CatGodClass>();
        if (StringUtils.isNotBlank(catGodClass.getClassName())){
            lqw.like(CatGodClass::getClassName ,catGodClass.getClassName());
        }
        if (StringUtils.isNotBlank(catGodClass.getIntor())){
            lqw.eq(CatGodClass::getIntor ,catGodClass.getIntor());
        }
        if (catGodClass.getCreateData() != null){
            lqw.eq(CatGodClass::getCreateData ,catGodClass.getCreateData());
        }
        if (catGodClass.getStatus() != null){
            lqw.eq(CatGodClass::getStatus ,catGodClass.getStatus());
        }
        List<CatGodClass> list = iCatGodClassService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 查询大神评论标签列表
     */
    @ApiOperation(value = "查询大神评论标签list",notes = "查询大神评论标签list",response = TableDataInfo.class)
    @GetMapping("/all")
    public AjaxResult all(){
        List<CatGodClass> list = iCatGodClassService.list();
        return AjaxResult.success(list);
    }

    /**
     * 导出大神评论标签列表
     */
    @ApiOperation(value = "导出大神评论标签列表",notes = "导出大神评论标签列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:class:export')" )
    @Log(title = "大神评论标签" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatGodClass catGodClass) {
        LambdaQueryWrapper<CatGodClass> lqw = new LambdaQueryWrapper<CatGodClass>(catGodClass);
        List<CatGodClass> list = iCatGodClassService.list(lqw);
        ExcelUtil<CatGodClass> util = new ExcelUtil<CatGodClass>(CatGodClass. class);
        return util.exportExcel(list, "class" );
    }

    /**
     * 获取大神评论标签详细信息
     */
    @ApiOperation(value = "获取大神评论标签详细信息",notes = "获取大神评论标签详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:class:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatGodClassService.getById(id));
    }

    /**
     * 新增大神评论标签
     */
    @ApiOperation(value = "新增大神评论标签",notes = "新增大神评论标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:class:add')" )
    @Log(title = "大神评论标签" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatGodClass catGodClass) {
        catGodClass.setCreateData(new Date());
        catGodClass.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatGodClassService.save(catGodClass) ? 1 : 0);
    }

    /**
     * 修改大神评论标签
     */
    @ApiOperation(value = "修改大神评论标签",notes = "修改大神评论标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:class:edit')" )
    @Log(title = "大神评论标签" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatGodClass catGodClass) {
        catGodClass.setCreateData(new Date());
        catGodClass.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatGodClassService.updateById(catGodClass) ? 1 : 0);
    }

    /**
     * 删除大神评论标签
     */
    @ApiOperation(value = "删除大神评论标签",notes = "删除大神评论标签",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:class:remove')" )
    @Log(title = "大神评论标签" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatGodClassService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
